/**
 * @Description: 消费记录API
 * @author tao.xie
 * @date 2019-02-25
 */

import ajaxAsync from '../../src/utils/ajaxAsync'
import TradeItem from '../model/TradeItem.js'

async function getCustomRecordList (cardNo, pageIndex, pageCapacity = 10) {
  let res = await ajaxAsync('/vcard/trade/list2', {
    CARD_NO: cardNo,
    PAGE_INDEX: pageIndex,
    PAGE_CAPACITY: pageCapacity
  })
  let count = res.COUNT
  let customRecordList = []
  if (count === 0) {
    return { COUNT: 0, LIST: customRecordList }
  } else {
    res.LIST.map(item => {
      customRecordList.push(new TradeItem(
        item.MONTH,
        item.RECHARGE_FEE,
        item.PAY_FEE,
        item.REFUND_FEE,
        item.CASH_FEE,
        item.TRADE_DETAIL
      ))
    })

    return { COUNT: count, LIST: customRecordList }
  }
}

export default getCustomRecordList